home *** CD-ROM | disk | FTP | other *** search
- /************************************
- File: MyWindow.c
- *************************************/
- /**********************
- Include files
- ***********************/
- #include "MyWindow.h"
- #include "String.h"
-
- /**********************
- Constants
- ***********************/
- #define TRUE 1
- #define FALSE 0
- #define NIL 0
-
- #define I_A_Button 15
- #define I_A_Checkbox 21
- #define I_Radio_3 20
- #define I_Radio_2 19
- #define I_Radio_1 16
- #define I_Scroll_bar 11
- #define PictureID 14
- #define PopUpID 51
-
- /**********************
- Globals
- ***********************/
- extern char forPrinting;
-
- WindowPtr MyWindow;
- static ControlHandle ScrollVHandle;
- static ControlHandle C_A_Button;
- static ControlHandle C_A_Checkbox;
- static ControlHandle R1Control[4];
- static char ChangedSelection;
- static TEHandle theTE;
- static ListHandle List_I_AList;
- static Rect Rect_I_AList;
- static short Popup_I_PopUp;
-
- /**********************
- Init_MyWindow()
- ***********************/
- void Init_MyWindow()
- { /* Init_MyWindow() */
- MyWindow = NIL;
- } /* Init_MyWindow() */
-
- /**********************
- Close_MyWindow() closes window
- ***********************/
- void Close_MyWindow(whichWindow,theInput)
- WindowPtr whichWindow;
- TEHandle *theInput;
- { /* Close_MyWindow() */
- if ((MyWindow != NIL) &&
- ((MyWindow == whichWindow) || (whichWindow == (WindowPtr)-1))) {
-
- /* dispose of TE record and window */
- if (*theInput == theTE)
- *theInput = NIL;
- DisposeWindow(MyWindow);
- MyWindow = NIL;
- }
- } /* Close_MyWindow() */
-
- /**********************
- Resized_MyWindow() handles re-sizing of window
- ***********************/
- void Resized_MyWindow(OldRect,whichWindow)
- Rect *OldRect;
- WindowPtr whichWindow;
- { /* Resized_MyWindow() */
- WindowPtr SavePort;
- Rect tempRect, temp2Rect;
- short Index;
-
- if (MyWindow == whichWindow) { /* MyWindow */
- GetPort(&SavePort);
- SetPort(MyWindow);
-
- if (ScrollVHandle != NIL) { /* take care of scrollbar */
- HLock((Handle)ScrollVHandle);
-
- /* Invalidate old rectangle of scrollbar */
- tempRect.left = (*ScrollVHandle)->contrlRect.left-4;
- tempRect.top = (*ScrollVHandle)->contrlRect.top;
- tempRect.right = (*ScrollVHandle)->contrlRect.right;
- tempRect.bottom = (*ScrollVHandle)->contrlRect.bottom+16;
- InvalRect(&tempRect);
-
- /* get old rect */
- tempRect.left = (*ScrollVHandle)->contrlRect.left;
- tempRect.bottom = (*ScrollVHandle)->contrlRect.bottom;
- temp2Rect.left = MyWindow->portRect.left;
- temp2Rect.top = MyWindow->portRect.top;
- temp2Rect.right = MyWindow->portRect.right;
- temp2Rect.bottom = MyWindow->portRect.bottom;
- Index = temp2Rect.bottom - temp2Rect.top - 13;
- tempRect.top = -1;
-
- /* move control */
- HideControl(ScrollVHandle);
- SizeControl(ScrollVHandle, 16,Index);
- MoveControl(ScrollVHandle,
- temp2Rect.right - temp2Rect.left-15,tempRect.top);
- ShowControl(ScrollVHandle);
- HUnlock((Handle)ScrollVHandle);
- } /* take care of scrollbar */
-
- SetPort(SavePort);
- } /* MyWindow */
- } /* Resized_MyWindow() */
-
- /**********************
- UpDate_MyWindow() handles updates and printing of MyWindow
- ***********************/
- void UpDate_MyWindow(whichWindow)
- WindowPtr whichWindow;
- { /* UpDate_MyWindow() */
- WindowPtr SavePort, OldPort;
- PicHandle Pic_Handle;
- Str255 sTemp;
- Rect tempRect;
-
- if ((MyWindow != NIL) && (MyWindow == whichWindow)) { /* MyWindow */
- /* Draw Picture */
- Pic_Handle = GetPicture(PictureID);
- SetRect(&tempRect, 151,100,215,182);
- if (Pic_Handle != NIL)
- DrawPicture ( Pic_Handle , &tempRect);
-
- /* Draw static text */
- TextFont(systemFont);
- SetRect(&tempRect, 9,45,75,62);
- strcpy((char *) &sTemp,"Message:");
- CtoPstr((char *)&sTemp);
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
- TextFont(applFont);
-
- /* Draw or Print TE record */
- SetRect(&tempRect, 8,68,124,90);
- FrameRect(&tempRect);
- InsetRect(&tempRect,3,3);
- if (theTE != NIL)
- if (!forPrinting)
- TEUpdate(&tempRect,theTE); /* normal updating */
- else {
- OldPort = (**theTE).inPort; /* change port in TE */
- GetPort(&SavePort);
- (**theTE).inPort = SavePort;
- TEUpdate(&tempRect,theTE); /* normal updating */
- (**theTE).inPort = OldPort; /* restore port in TE */
- }
-
- /* Draw or Print List */
- SetRect(&tempRect, 4,115,148,179);
- tempRect.right = tempRect.right - 15;
- InsetRect(&tempRect,-1,-1);
- FrameRect(&tempRect);
- if (List_I_AList != NIL)
- if (!forPrinting)
- LUpdate(MyWindow->visRgn,List_I_AList);
- else
- PrintList(List_I_AList); /* call print list */
-
- /* Draw PopUp Menu */
- TextSize(12);
- TextFont(systemFont);
- TextSize(12);
- MoveTo(86,56);
- DrawString("\pPopUp:");
- SetRect(&tempRect,133,43,197,60);
- EraseRect(&tempRect);
- MoveTo(146,56);
- switch (Popup_I_PopUp) { /* Draw Current PopUp Selection */
- case 1:
- DrawString("\pFirst");
- break;
- case 2:
- DrawString("\pSecond");
- break;
- case 3:
- DrawString("\pThird");
- break;
- default:
- DrawString("\p????");
- break;
- }
- FrameRect(&tempRect);
- MoveTo(tempRect.left + 1, tempRect.bottom);
- LineTo(tempRect.right, tempRect.bottom);
- LineTo(tempRect.right, tempRect.top + 1);
- TextSize(12);
- TextFont(applFont);
-
- /* Draw or Print Controls */
- if (!forPrinting)
- DrawControls(MyWindow);
- else
- PrintControls(((WindowPeek) MyWindow)->controlList);
- DrawGrowIcon(MyWindow);
- } /* MyWindow */
- } /* UpDate_MyWindow() */
-
- /**********************
- HandleScrollBar() takes care of scrollbar
- ***********************/
- static void HandleScrollBar(code, Start, Stop, Increment, LIncrement, theControl,myPt)
- short code;
- short Start;
- short Stop;
- short LIncrement,Increment;
- ControlHandle theControl;
- Point myPt;
- { /* HandleScrollBar() */
- short theValue;
- long MaxTick;
-
- do { /* button pressed */
- HiliteControl(theControl, code);
- theValue = GetCtlValue(theControl);
-
- if (code == inUpButton) {
- theValue = theValue - Increment;
- if (theValue < Start)
- theValue = Start;
- }
- if (code == inDownButton) {
- theValue = theValue + Increment;
- if (theValue > Stop)
- theValue = Stop;
- }
- if (code == inPageUp) {
- theValue = theValue - LIncrement;
- if (theValue < Start)
- theValue = Start;
- }
- if (code == inPageDown) {
- theValue = theValue + LIncrement;
- if (theValue > Stop)
- theValue = Stop;
- }
- if (code == inThumb) {
- code = TrackControl(theControl, myPt, NIL);
- theValue = GetCtlValue(theControl);
- }
-
- SetCtlValue(theControl, theValue);
-
- MaxTick = TickCount() + 9; /* delay */
- do { } while ( (Button() == TRUE) && (TickCount() <= MaxTick));
-
- HiliteControl(theControl, 0);/* Lighten the arrow */
- } while (StillDown( ) == TRUE); /* button pressed */
- } /* HandleScrollBar() */
-
- /**********************
- Open_MyWindow() opens MyWindow
- ***********************/
- void Open_MyWindow(theInput)
- TEHandle *theInput;
- { /* Open_MyWindow() */
- short Index;
- Rect dataBounds;
- Point cSize;
- short theRow;
- Rect tempRect, temp2Rect;
- Str255 sTemp;
-
- if (MyWindow == NIL) {
- MyWindow = GetNewWindow(1,NIL, (WindowPtr)-1);
- SetPort(MyWindow);
-
- /* Get Controls */
- C_A_Button = GetNewControl(I_A_Button,MyWindow);
- C_A_Checkbox = GetNewControl(I_A_Checkbox,MyWindow);
- R1Control[1] = GetNewControl ( I_Radio_1 , MyWindow );
- R1Control[2] = GetNewControl ( I_Radio_2 , MyWindow );
- R1Control[3] = GetNewControl ( I_Radio_3 , MyWindow );
-
- /* get scrollbar */
- SetRect(&tempRect,310,-1,326,195);
- temp2Rect.left = MyWindow->portRect.left;
- temp2Rect.right = MyWindow->portRect.right;
- temp2Rect.top = MyWindow->portRect.top;
- temp2Rect.bottom = MyWindow->portRect.bottom;
- ScrollVHandle = GetNewControl(I_Scroll_bar,MyWindow);
- Index = temp2Rect.bottom - temp2Rect.top - 13;
- tempRect.top = 0;
- SizeControl(ScrollVHandle, 16,Index);
- MoveControl(ScrollVHandle, temp2Rect.right - temp2Rect.left-15,tempRect.top-1);
-
- /* get TE record */
- SetRect(&tempRect, 8,68,124,90);
- FrameRect(&tempRect);
- InsetRect(&tempRect,3,3);
- theTE= TENew(&tempRect,&tempRect);
- if (*theInput != NIL)
- TEDeactivate(*theInput);
- *theInput = theTE;
- HLock((Handle)theTE);
- (*theTE)->txFont = systemFont;
- (*theTE)->fontAscent = 12;
- (*theTE)->lineHeight = 12 + 3 + 1;
- HUnlock((Handle)theTE);
- strcpy((char *)&sTemp,"Hello there!");
- CtoPstr((char *)&sTemp);
- TESetText(&sTemp[1],sTemp[0],theTE);
- TEActivate(theTE);
- TEUpdate(&tempRect,theTE);
- TextFont(applFont);
-
- /* get list */
- SetRect(&tempRect, 4,115,148,179);
- Rect_I_AList = tempRect;
- tempRect.right = tempRect.right - 15;
- InsetRect(&tempRect,-1,-1);
- FrameRect(&tempRect);
- InsetRect(&tempRect,1,1);
- SetRect(&dataBounds,0,0,1,0);
- cSize.h = tempRect.right - tempRect.left;
- cSize.v = 0;
- List_I_AList = LNew(&tempRect,&dataBounds,cSize,0,MyWindow,TRUE,FALSE,FALSE,TRUE);
- (*List_I_AList)->selFlags = lOnlyOne + lNoNilHilite;
- LDoDraw(TRUE,List_I_AList);
-
- /* add items to list */
- cSize.h = 0;
- strcpy((char *) &sTemp,"\pFirst Item");
- theRow = LAddRow(1, 200, List_I_AList);
- cSize.v = theRow;
- LSetCell(&sTemp[1], sTemp[0], cSize, List_I_AList);
- LDraw(cSize, List_I_AList);
-
- strcpy((char *)&sTemp,"\pSecond Item");
- theRow = LAddRow(1, 200, List_I_AList);
- cSize.v = theRow;
- LSetCell(&sTemp[1], sTemp[0], cSize, List_I_AList);
- LDraw(cSize, List_I_AList);
-
- strcpy((char *)&sTemp,"\pThird Item");
- theRow = LAddRow(1, 200, List_I_AList);
- cSize.v = theRow;
- LSetCell(&sTemp[1], sTemp[0], cSize, List_I_AList);
- LDraw(cSize, List_I_AList);
-
- strcpy((char *)&sTemp,"\pFourth Item");
- theRow = LAddRow(1, 200, List_I_AList);
- cSize.v = theRow;
- LSetCell(&sTemp[1], sTemp[0], cSize, List_I_AList);
- LDraw(cSize, List_I_AList);
-
- strcpy((char *)&sTemp,"\pFifth Item");
- theRow = LAddRow(1, 200, List_I_AList);
- cSize.v = theRow;
- LSetCell(&sTemp[1], sTemp[0], cSize, List_I_AList);
- LDraw(cSize, List_I_AList);
-
- cSize.h = 0;
- cSize.v = 0;
- LSetSelect(TRUE,cSize,List_I_AList);
- TextSize(12);
-
- /* set up PopUp menu */
- Popup_I_PopUp = 1;
- ShowWindow(MyWindow);
- SelectWindow(MyWindow);
- }
- else
- SelectWindow(MyWindow);
- } /* Open_MyWindow() */
-
- /**********************
- Do_A_Checkbox() Handles checkbox and radios
- ***********************/
- static void Do_A_Checkbox(theControl)
- ControlHandle theControl;
- { /* Do_A_Checkbox() */
- short RefCon;
- short theValue, Index;
-
- RefCon = GetCRefCon(theControl);
- theValue = GetCtlValue(theControl);
- theValue = (theValue + 1) & 1;
-
- switch (RefCon) { /* switch on type */
- case I_A_Checkbox:
- SetCtlValue(theControl, theValue);
- break;
-
- case I_Radio_1:
- case I_Radio_2:
- case I_Radio_3:
- for (Index = 1; Index < 4; Index++) /* clear radios first */
- SetCtlValue(R1Control[Index],0);
- SetCtlValue(theControl, 1);
- break;
- default:
- break;
- } /* switch on type */
- } /* Do_A_Checkbox() */
-
- /**********************
- Do_MyWindow()
- ***********************/
- void Do_MyWindow(myEvent, theInput)
- EventRecord *myEvent;
- TEHandle *theInput;
- { /* Do_MyWindow() */
- short code;
- WindowPtr whichWindow;
- Point myPt;
- ControlHandle theControl;
- char DoubleClick;
- long theCell;
- Rect tempRect;
- MenuHandle tempMenu;
- long Result;
-
- if (MyWindow != NIL) { /* MyWindow */
- code = FindWindow(myEvent->where, &whichWindow);
-
- if ((myEvent->what == mouseDown) && (MyWindow == whichWindow)) { /* mouse event */
- myPt = myEvent->where;
- GlobalToLocal(&myPt);
-
- SetRect(&tempRect, 8,68,124,90);
- if (PtInRect(myPt,&tempRect) == TRUE) { /* handle TE record */
- if (*theInput != NIL)
- TEDeactivate(*theInput);
- *theInput = theTE;
- TEActivate(*theInput);
- TEClick(myPt, FALSE, theTE);
- } /* handle TE record */
-
- if (PtInRect(myPt,&Rect_I_AList) == TRUE) { /* handle list */
- DoubleClick = LClick(myPt, myEvent->modifiers, List_I_AList);
- theCell = LLastClick(List_I_AList);
- } /* handle list */
-
- SetRect(&tempRect, 81,42,204,62);
- if ( PtInRect ( myPt , &tempRect ) == TRUE ) { /* in PopUp */
- ChangedSelection = FALSE;
- tempMenu = GetMenu(PopUpID);
- if (tempMenu != NIL) { /* Good Menu */
-
- /* Select Menu Item */
- InsertMenu (tempMenu,-1);
- SetRect(&tempRect,81,44,133,60);
- InvertRect(&tempRect);
- myPt.v = 44;
- myPt.h = 133;
- LocalToGlobal(&myPt);
- CheckItem(tempMenu,Popup_I_PopUp,TRUE);
- Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h, Popup_I_PopUp);
- if ((Popup_I_PopUp!= LoWord(Result)) && (LoWord(Result) > 0)) {
- CheckItem(tempMenu,Popup_I_PopUp,FALSE);
- ChangedSelection = TRUE;
- Popup_I_PopUp= LoWord(Result);
- }
- else
- CheckItem(tempMenu,Popup_I_PopUp,FALSE);
- DeleteMenu(PopUpID);
-
- /* clean up */
- InvertRect(&tempRect);
- if (ChangedSelection == TRUE) { /* show new selection */
- SetRect(&tempRect,134,44,196,59);
- EraseRect(&tempRect);
- MoveTo(tempRect.left + 12,tempRect.top + 12);
- TextFont(systemFont);
- switch (Popup_I_PopUp) {
- case 1:
- DrawString("\pFirst");
- break;
- case 2:
- DrawString("\pSecond");
- break;
- case 3:
- DrawString("\pThird");
- break;
- default:
- break;
- }
- TextFont(applFont);
- } /* show new selection */
- } /* Good Menu */
- whichWindow = NIL;
- } /* in PopUp */
-
- } /* mouse event */
-
- if ((MyWindow == whichWindow) && (code == inContent)) { /* handle controls */
- code = FindControl(myPt, whichWindow, &theControl);
-
- if ((code == inUpButton) || (code == inDownButton)
- || (code == inThumb) || (code == inPageDown) || (code == inPageUp))
- HandleScrollBar(code,1,100,1,10,theControl,myPt);
- if (code != 0)
- code = TrackControl(theControl,myPt, NIL);
- if (code == inCheckBox)
- Do_A_Checkbox(theControl);
- } /* handle controls */
- } /* MyWindow */
- } /* Do_MyWindow() */
-